import type { VNode } from 'vue';
import { ComputedRef, Ref } from 'vue';
import { AllBizScopeEnum } from '@/commonModule/constants';
import type { FormRules } from 'element-plus';

export interface IFormConfig {
  rules?: any;
  labelWidth?: number;
  labelPosition?: 'left' | 'right' | 'top';
  gutter?: number;
}
export interface IPostParams {
  groupType: 'PCF_MODEL_INFO'; // TODO 需要维护map
  scope: keyof typeof AllBizScopeEnum;
  needRename: false;
}
export interface IFileConfig {
  accept?: string; // 文件格式 例：.jpg, .png, .jpeg, .pdf
  tip?: string; // 提示文字
  limit?: number; // 文件个数限制
  postParams?: IPostParams;
}
export interface IFormSchema {
  field: string;
  valueField?: string; // 用来替换默认的value名称
  unitField?: string; // 单位的field
  label: string | VNode;
  labelWidth?: string | number;
  placeholder?: string;
  rules?: FormRules; // 规则
  defaultValue?: string; // 默认值
  span?: number; //行大小
  slot?: string;
  tipSlot?: string; // 提示框插槽
  disabled?: boolean;
  clearable?: boolean;
  required?: boolean;
  tip?: string; // 提示文案
  style?: string;
  fixedOption?: string;
  options?: LabelValueOptions[] | any[];
  fileConfig?: IFileConfig; // type为upload 才需要配置
  type?:
    | 'input'
    | 'textarea'
    | 'select'
    | 'datePicker'
    | 'cascader'
    | 'radio'
    | 'checkbox'
    | 'input-unit'
    | 'upload'
    | 'standardRadio';
  format?: string;
  dateType?: string;
  onFormChange?: (searchForm: any) => void;
  filterable?: boolean;
}

export interface IFormGroupInstance {
  name?: string;
  modelVal?: ComputedRef;
  formConfig?: IFormConfig;
  validateArr?: Ref;
  changeEvent?: Fn<any>;
}

export const MITT_KEY = 'c.form.validate';
